package annotation;

import java.lang.reflect.Field;

/**
 * @Description: 注解处理器
 * @author: me@longlonggo.com
 * @Date: 2018/12/11
 */
public class FruitInfoContorller {
    public static void getFruitInfo(Class<?> clazz) {
        String strFruitName = "水果名称：";
        String strFruitColor = "水果颜色：";
        String strFruitProvider = "水果供应商：";

        Field[] fields = clazz.getDeclaredFields();
        for (Field f : fields) {
            if (f.isAnnotationPresent(FruitName.class)) {
                FruitName fruitName = (FruitName) f.getAnnotation(FruitName.class);
                strFruitName += fruitName.value();
                System.out.println(strFruitName);
            } else if (f.isAnnotationPresent(FruitColor.class)) {
                FruitColor fruitColor = f.getAnnotation(FruitColor.class);
                strFruitColor += fruitColor.fruitColor();
                System.out.println(strFruitColor);
            } else if (f.isAnnotationPresent(FruitProvider.class)) {
                FruitProvider fruitProvider = f.getAnnotation(FruitProvider.class);
                strFruitProvider += "供应商编号：" + fruitProvider.id()
                        + " 供应商名称：" + fruitProvider.name()
                        + " 供应商地址：" + fruitProvider.address();
                System.out.println(strFruitProvider);
            }
        }
    }
}
